package com.bw.domain;

import lombok.Data;

import java.io.Serializable;

@Data
public class BResult<T> implements Serializable {

    // 成功值,默认为1
    private static final int SUCCESS_CODE = 1;
    // 失败值,默认为0
    private static final int ERROR_CODE = 0;

    //状态码
    private int code;
    //提示消息
    private String msg;
    //返回数据
    private T data;
    private BResult(){

    }
    private BResult(int code){
        this.code = code;
    }

    private BResult(String msg){
        this.msg = msg;
    }
    private BResult(int code, T data){
        this.code = code;
        this.data = data;
    }
    private BResult(int code, String msg){
        this.code = code;
        this.msg = msg;
    }
    private BResult(int code, String msg, T data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BResult<T> success(){
        return new BResult<T>(SUCCESS_CODE,"success");
    }

    public static <T> BResult<T> success(T data){
        return new BResult<T>(SUCCESS_CODE,data);
    }
    public static <T> BResult<T> success(String msg, T data){
        return new BResult<T>(SUCCESS_CODE,msg,data);
    }

    public static <T> BResult<T> error(){
        return new BResult<T>(ERROR_CODE,"error");
    }
    public static <T> BResult<T> error(String msg){
        return new BResult<T>(ERROR_CODE,msg);
    }
    public static <T> BResult<T> error(int code, String msg){
        return new BResult<T>(code,msg);
    }

}



